package edu.guet.cn.blogbasics.common;

import lombok.Getter;

/**
 * @Auther: hejianding
 * @Date: 2021/4/8 14:25
 * @Version: 1.0
 */
@Getter
public enum ResultEnum {
    /**
     * description: 认证结果状态码及信息
     *
     * @param null
     * @return
     */

    SELECT_WORKSHEET_DONE_SUCCESS(320, "以完成任务如下"),
    SELECT_WORKSHEET_DONE_FAILED(321, "以完成任务如下"),


    SUBMIT_WORKSHEET_SUCCESS(316, "任务已完成"),
    SUBMIT_WORKSHEET_FAILED(317, "任务提交失败"),

    DELETE_WORKSHEET_SUCCESS(314, "删除任务成功"),
    DELETE_WORKSHEET_FAILED(315, "删除任务失败"),

    UPDATE_WORKSHEET_SUCCESS(311, "更新任务成功"),
    UPDATE_WORKSHEET_FAILED(312, "更新信息不能为空"),
    ADD_WORKSHEET_SUCCESS(310, "添加成功"),
    ADD_WORKSHEET_FAILED1(309, "请填写计划和日期"),
    ADD_WORKSHEET_FAILED2(309, "任务重复"),

    UPDATE_PASSWORD_SUCCESS(306, "密码更新成功"),
    UPDATE_PASSWORD_FAILED(307, "更新失败，密码错误"),
    UPDATE_SUCCESS(305,"更新成功"),
    WRITE_MESSAGE(301,"请完善注册信息"),
    USERNAME_EXIST(302,"用户名已经存在"),
    NICKNAME_EXIST(303,"昵称已经存在"),
    ADD_SUCCESSES(304,"注册成功"),
    SUCCESS(101,"成功"),
    FAILURE(102,"失败"),
    USER_NEED_AUTHORITIES(201,"用户未登录"),
    USER_LOGIN_FAILED(202,"用户账号或密码错误"),
    USER_LOGIN_SUCCESS(203,"用户登录成功"),
    USER_NO_ACCESS(204,"用户无权访问"),
    USER_LOGOUT_SUCCESS(205,"用户登出成功"),
    TOKEN_IS_BLACKLIST(206,"此token为黑名单"),
    LOGIN_IS_OVERDUE(207,"登录已失效"),
    ;

    private Integer code;

    private String message;

    ResultEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * description: 通过code返回message
     *
     * @param code
     * @return com.shiep.jwtauth.common.ResultEnum
     */
    public static ResultEnum parse(int code){
        ResultEnum[] values = values();
        for (ResultEnum value : values) {
            if(value.getCode() == code){
                return value;
            }
        }
        throw  new RuntimeException("Unknown code of ResultEnum");
    }

}
